<template>
  <div>
    <hm_header title="我的关注">
      <template #left>
        <van-icon name="arrow-left" @click="$router.go(-1)" />
      </template>
    </hm_header>
    <div class="list">
      <div class="box" v-for="(item,index) in follows" :key="item.id">
        <img :src="item.head_img" alt />
        <div class="center">
          <p>{{item.nickname}}</p>
          <span>2019-9-9</span>
        </div>
        <span @click="cancelFollow(item.id,index)">取消关注</span>
      </div>
    </div>
  </div>
</template>

<script>
import hm_header from "@/components/hm_header.vue";
import { getFollows, unFllowsUser } from "@/apis/user.js";
import axios from "@/utils/request.js";
export default {
  components: {
    hm_header
  },
  data() {
    return {
      follows: []
    };
  },
  async mounted() {
    this.follows = (await getFollows()).data.data.map(v => {
      v.head_img = axios.defaults.baseURL + v.head_img;
      return v;
    });

    console.log(this.follows);
  },
  methods: {
    async cancelFollow(id, index) {
      let res = await unFllowsUser(id);
      this.$toast.success(res.data.message);
      this.follows.splice(index, 1);
    }
  }
};
</script>

<style lang="less" scoped>
.list {
  .box {
    display: flex;
    padding: 25px 10px;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ccc;
    > img {
      display: block;
      width: 50/360 * 100vw;
      height: 50/360 * 100vw;
      border-radius: 50%;
      padding: 0 10px;
    }
    > .center {
      flex: 1;
      > p {
        line-height: 30px;
        font-size: 14px;
      }
      > span {
        font-size: 12px;
        color: #999;
      }
    }
    > span {
      height: 30px;
      background-color: #eee;
      font-size: 13px;
      border-radius: 30px;
      line-height: 30px;
      padding: 0px 15px;
    }
  }
}
</style>